package priv.yiyuan.example.design.flyweight;

/**
 * 打折价格计算策略
 * <p>
 * 享元模式-具体享元
 * 策略模式-具体策略
 *
 * @author YiYuan
 * @data 2025/9/19
 * @apoNote
 */
public class DiscountStrategy implements PriceCalculationStrategy {

    // 内在状态 折扣率
    private double discountRate;

    public DiscountStrategy(double discountRate) {
        this.discountRate = discountRate;
        System.out.println("创建新的折扣策略享元: " + (discountRate * 100) + "%");
    }

    @Override
    public double calculatePrice(double originalPrice) {
        return originalPrice * (1 - discountRate);
    }
}
